package net.dengzixu.java.homework.period23;

/**
 * @author Deng Zixu <admin@dengzixu.com>
 */
public class ShapeTest {
    public static void main(String[] args) {
        Shape rectangle = new Rectangle(3, 4);
        Shape circle = new Circle(2);
        System.out.println("Rectangle area is: " + rectangle.findArea());
        System.out.println("Circle area is: " + circle.findArea());


        Rectangle rectangle1 = new Rectangle(5, 6);
        Circle circle1 = new Circle(4);
        System.out.println("Rectangle area is: " + rectangle1.findArea());
        System.out.println("Circle area is: " + circle1.findArea());

        ShapeTest shapeTest = new ShapeTest();

        shapeTest.callFindArea(rectangle);
        shapeTest.callFindArea(circle);
    }

    public void callFindArea(Shape shape) {
        System.out.println(shape.getClass().getSimpleName() + " area is: " + shape.findArea());
    }
}


abstract class Shape {
    abstract double findArea();
}

class Rectangle extends Shape {
    private final double lSide;
    private final double sSide;

    public Rectangle(double lSide, double sSide) {
        this.lSide = lSide;
        this.sSide = sSide;
    }

    @Override
    double findArea() {
        return lSide * sSide;
    }
}

class Circle extends Shape {
    private final double r;

    public Circle(double r) {
        this.r = r;
    }

    @Override
    double findArea() {
        return Math.PI * Math.pow(r, 2);
    }
}